home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
lisp
/
eulisp
/
mpfeel.lha
/
MPFeel
/
Plurals
/
Random
/
p_random_init.m
< prev
next >
Wrap
Text File
|
1992-04-27
|
1KB
|
61 lines
/******************************************************************************
A portable plural random number generator based on three linear
congruential generators. -- Numerical Recipes in C pp. 210
Copyright 1991,1992 Lee Iverson
Author:
Lee Iverson <leei@mcrcim.mcgill.edu>,
McGill Research Centre for Intelligent Machines (McRCIM)
See "copyright.h" for complete copyright information.
******************************************************************************/
static char RCSid[] =
"$Id: p_random_init.m,v 1.2 92/01/23 17:34:14 leei Exp $";
#include "copyright.h"
#include <values.h>
#include <math.h>
#include <sys/time.h>
#include "p_randomI.h"
char rand_init__ = 0;
plural long ix1__, ix2__, ix3__;
plural float r__[98];
/* Initialize the random number generator from time of day. */
void
init_p_random(seed)
int seed;
{
register plural long p_seed;
register int j;
if ( seed ) {
p_seed = seed + 17*iproc;
} else {
struct timeval t;
struct timezone tz;
gettimeofday(&t,&tz);
p_seed = t.tv_sec+17*iproc;
}
++rand_init__;
ix1__ = (IC1 + p_seed) % M1;
ix1__ = (IA1*ix1__ + IC1) % M1;
ix2__ = ix1__ % M2;
ix1__ = (IA1*ix1__ + IC1) % M1;
ix3__ = ix1__ % M3;
for ( j=1; j < 98; ++j ) {
ix1__ = (IA1*ix1__ + IC1) % M1;
ix2__ = (IA2*ix2__ + IC2) % M2;
r__[j] = (ix1__+ix2__*RM2)*RM1;
}
}